let express = require("express")()
const { request } = require("express");
let expressStatic = require("express-static")
const port = 8080
var mysql = require('mysql');
var sql = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: '123456',
    database: 'news',
    timezone: '08:00'
});

sql.connect();
//列表
express.get("/getnewslist", (request, response) => {
    sql.query(`SELECT id,title FROM news`, (error, data) => {
        if (error) {
            console.log(error)
            response.send("error")
        } else {
            response.send(data)
        }
    })
})

//详情页
express.get("/getnews", (request, response) => {
    let id = request.query.id
    sql.query(`select * from news where id=${id}`, (error, data) => {
        if (error) {
            console.log(error)
            response.send("error")
        } else {
            response.send(data[0])
        }
    })
})







express.use(expressStatic(__dirname + '/static'))
express.listen(port)